package com.paomi.client.activity.detail.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.paomi.client.R;
import com.paomi.client.activity.detail.model.Comment;
import com.paomi.client.utils.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by pc on 2018/10/29
 * Describe:
 * com.paomi.client.activity.detail.adapter
 */
public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.ViewHolder> {


    private Activity mcontext;
    private List<Comment> ticketList = new ArrayList<>();

    public CommentListAdapter(Activity comtext) {
        mcontext = comtext;
    }

    public void setData(List<Comment> jsonList) {
        ticketList = jsonList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mcontext).inflate(R.layout.item_comment_list, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Comment comment=ticketList.get(position);
        holder.myComment.setText(comment.getContent());
        if(comment.getReplyComments()!=null &&comment.getReplyComments().getData().size()>0){
            holder.vieList.setVisibility(View.VISIBLE);
            holder.vieList.setLayoutManager(Util.getRecyclerViewManager(false,mcontext));
            ReplyItemAdapter replyItemAdapter=new ReplyItemAdapter(mcontext);
            holder.vieList.setAdapter(replyItemAdapter);
            replyItemAdapter.setData(comment.getReplyComments().getData());
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                mcontext.startActivity(new Intent(mcontext, DetailTicketActivity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return ticketList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.user_image)
        RoundedImageView userImage;
        @BindView(R.id.comment_user)
        TextView commentUser;
        @BindView(R.id.my_comment)
        TextView myComment;
        @BindView(R.id.comment_tip)
        TextView commentTip;
        @BindView(R.id.comment_msg_num)
        TextView commentMsgNum;
        @BindView(R.id.msg_num_iv)
        TextView msgNumIv;
        @BindView(R.id.praise_num)
        TextView praiseNum;
        @BindView(R.id.praise_iv)
        TextView praiseIv;
        @BindView(R.id.comment_content)
        TextView commentContent;
        @BindView(R.id.comment_time)
        TextView commentTime;
        @BindView(R.id.comment_delete)
        TextView commentDelete;
        @BindView(R.id.reply_list)
        RecyclerView vieList;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
